﻿package mortal.component.window
{
    import com.gengine.keyBoard.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.game.manager.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.interfaces.*;

    public class SmallWindow extends BaseWindow
    {
        private var _sp:GSprite;

        public function SmallWindow(param1:ILayer = null)
        {
            super(param1);
            return;
        }// end function

        override protected function configParams() : void
        {
            titleHeight = 29;
            paddingBottom = 5;
            paddingLeft = 7;
            blurTop = 5;
            blurBottom = 4;
            blurLeft = 6;
            blurRight = 5;
            _contentX = blurLeft;
            _contentY = blurTop;
            return;
        }// end function

        public function get isFlic() : Boolean
        {
            return false;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            super.show(param1, param2);
            if (this.isFlic)
            {
                DisplayUtil.drawFullScreenMaskByStageXY(this._sp, 0, 0);
            }
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.target as DisplayObject;
            if (_loc_2 == this._sp)
            {
                Alert.flick(this);
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            if (this.isFlic)
            {
                this._sp = UIFactory.getUICompoment(GSprite) as GSprite;
                this._sp.mouseEnabled = true;
                this.addChildAt(this._sp, 0);
                this.configEventListener(MouseEvent.CLICK, this.clickHandler);
                this.layer = LayerManager.highestLayer;
                this.isForbidenDrag = true;
                KeyBoardManager.instance.cancelListener();
            }
            super.createDisposedChildrenImpl();
            return;
        }// end function

        override public function get isDragAble() : Boolean
        {
            if (this.isFlic)
            {
                return false;
            }
            return super.isDragAble;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            if (this._sp != null)
            {
                DisplayUtil.drawFullScreenMaskByStageXY(this._sp, 0, 0);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this.isFlic)
            {
                KeyBoardManager.instance.cancelListener();
                KeyBoardManager.instance.addListener();
            }
            this.configParams();
            if (this._sp != null)
            {
                this._sp.dispose(param1);
                this._sp = null;
            }
            return;
        }// end function

        override protected function setWindowCenter() : void
        {
            _windowCenter = UIFactory.bg(0, 0, -1, -1, this, ImagesConst.PanelBg);
            return;
        }// end function

        override protected function updateWindowCenterSize() : void
        {
            var _loc_1:* = this.width - paddingLeft - paddingRight - blurLeft - blurRight;
            var _loc_2:* = this.height - _titleHeight - paddingBottom - blurTop - blurBottom;
            if (_windowCenter)
            {
                _windowCenter.setSize(_loc_1, _loc_2);
                _windowCenter.x = paddingLeft + blurLeft;
                _windowCenter.y = _titleHeight + blurTop;
            }
            if (_windowCenter2)
            {
                _windowCenter2.setSize(_loc_1, _loc_2);
                _windowCenter2.x = paddingLeft + blurLeft;
                _windowCenter2.y = _titleHeight + blurTop;
            }
            if (_windowLine)
            {
                _windowLine.x = 2;
                _windowLine.y = _titleHeight + blurTop - 7;
                _windowLine.width = this.width - 4;
            }
            return;
        }// end function

        override protected function updateBtnSize() : void
        {
            if (_closeBtn)
            {
                _closeBtn.x = this.width - _closeBtn.width - 15 - _contentTopOf3DSprite.x + _contentX;
                _closeBtn.y = 7 - _contentTopOf3DSprite.y + _contentY;
            }
            return;
        }// end function

        override protected function updateDisplayList() : void
        {
            if (_titleChange)
            {
                _titleChange = false;
                if (_title)
                {
                    _title.y = 5;
                    _title.x = (this.width - _title.width) / 2;
                }
            }
            return;
        }// end function

        override protected function addWindowLine() : void
        {
            _windowLine = UIFactory.bg(0, 0, -1, -1, this, ImagesConst.SmallWindowBgLine);
            return;
        }// end function

    }
}
